import os
import sys
import pathlib
import strict_pam

def get_pam_features(context, pam_file):
    try:
        service = strict_pam.PamService(context, pam_file)
        if not service.is_complex():
            features = service.get_features()
            return [f.name() for f in features]
    except Exception as e:
        return [f"Error: {str(e)}"]
    return []

def main():
    pam_dir = "/etc/pam.d"
    
    context = strict_pam.Context()
    for filename in os.listdir(pam_dir):
        file_path = os.path.join(pam_dir, filename)
        if os.path.isfile(file_path):
            print(f"PAM file: {filename}")
            features = get_pam_features(context, filename)
            if features:
                print("  Features:")
                for feature in features:
                    print(f"    - {feature}")
            else:
                print("  No features found or complex service")
            print()

if __name__ == "__main__":
    main()
